<template>
  <div>
    <el-row>
      <!-- 下面部分 加做信息等 -->
      <el-row style="margin: 20px 0;width:99%" id="addMessage" v-if="!isSendDoctor">
        <div class="content-text">加做如下项目信息:</div>
        <template>
          <el-tabs
            class="borderPos"
            v-model="addItemCheckTab"
            type="card"
            @tab-click="addMesHandleClick"
          >
            <el-tab-pane class="border" label="特殊染色" name="addDyeing">
              <span slot="label">
                特殊染色
                <el-badge
                  v-if="stainingData.length > 0"
                  :value="stainingData.length"
                  class="tab-content-badge"
                ></el-badge>
              </span>
              <el-table :data="stainingData" border style="width: 100%">
                <el-table-column fixed="left" prop="projectName" label="项目名" width="180">
                </el-table-column>
                <el-table-column fixed label="操作" width="200">
                  <template slot-scope="scope">
                    <el-button
                      v-if="scope.row.statusName === '已上传'"
                      @click="LookItemCheck(scope.row)"
                      type="text"
                      size="small"
                      >查看</el-button
                    >
                    <el-button
                      v-if="scope.row.statusName !== '已上传' || scope.row.status === '正常'"
                      @click="removeItem(scope.row, 'staining')"
                      type="text"
                      size="small"
                    >
                      <font color="red">删除</font>
                    </el-button>
                    <el-button
                      v-if="
                        (scope.row.status === '机构做' && isSendDoctor) ||
                          (scope.row.status === '已付款' && !isSendDoctor)
                      "
                      @click="itemCheck(scope.row, 'staining')"
                      type="text"
                      size="small"
                      >{{ scope.row.statusName === '已上传' ? '重新上传' : '上传' }}
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column prop="statusName" label="当前状态" width="80"> </el-table-column>
                <el-table-column prop="submitDate" label="提交时间"> </el-table-column>
                <el-table-column prop="status" label="订单状态"> </el-table-column>
                <el-table-column label="备注" width="300">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.result"
                      placeholder="请输入备注"
                      class="input-form"
                      size="mini"
                    ></el-input>
                    <el-button
                      v-if="
                        (scope.row.status === '机构做' && isSendDoctor) ||
                          (scope.row.status === '已付款' && !isSendDoctor)
                      "
                      @click="saveRemark(scope.row)"
                      type="text"
                      size="small"
                      style="margin-left: 10px"
                      >保存</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
            <el-tab-pane class="border" label="分子病理" name="addItem">
              <span slot="label">
                分子病理
                <el-badge
                  v-if="fzblData.length > 0"
                  :value="fzblData.length"
                  class="tab-content-badge"
                ></el-badge>
              </span>
              <el-table :data="fzblData" border style="width: 100%">
                <el-table-column fixed="left" prop="projectName" label="项目名" width="180">
                </el-table-column>
                <el-table-column fixed label="操作" width="200">
                  <template slot-scope="scope">
                    <el-button
                      v-if="scope.row.statusName === '已上传'"
                      @click="LookItemCheck(scope.row)"
                      type="text"
                      size="small"
                      >查看</el-button
                    >
                    <el-button
                      v-if="scope.row.statusName !== '已上传' || scope.row.status === '正常'"
                      @click="removeItem(scope.row, 'molecularDetial')"
                      type="text"
                      size="small"
                    >
                      <font color="red">删除</font>
                    </el-button>
                    <el-button
                      v-if="
                        (scope.row.status === '机构做' && isSendDoctor) ||
                          (scope.row.status === '已付款' && !isSendDoctor)
                      "
                      @click="itemCheck(scope.row, 'molecularDetial')"
                      type="text"
                      size="small"
                      >{{ scope.row.statusName === '已上传' ? '重新上传' : '上传' }}
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column prop="statusName" label="当前状态" width="80"> </el-table-column>
                <el-table-column prop="submitDate" label="提交时间"> </el-table-column>
                <el-table-column prop="status" label="订单状态"> </el-table-column>
                <el-table-column label="备注" width="300">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.result"
                      placeholder="请输入备注"
                      class="input-form"
                      size="mini"
                    ></el-input>
                    <el-button
                      v-if="
                        (scope.row.status === '机构做' && isSendDoctor) ||
                          (scope.row.status === '已付款' && !isSendDoctor)
                      "
                      @click="saveRemark(scope.row)"
                      type="text"
                      size="small"
                      style="margin-left: 10px"
                      >保存</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
            <el-tab-pane class="border" label="免疫组化" name="immunology">
              <span slot="label">
                免疫组化
                <el-badge
                  v-if="ihcData.length > 0"
                  :value="ihcData.length"
                  class="tab-content-badge"
                ></el-badge>
              </span>
              <el-table :data="ihcData" border style="width: 100%">
                <el-table-column fixed="left" prop="projectName" label="项目名" width="180">
                </el-table-column>
                <el-table-column fixed label="操作" width="200">
                  <template slot-scope="scope">
                    <el-button
                      v-if="scope.row.statusName === '已上传'"
                      @click="LookItemCheck(scope.row)"
                      type="text"
                      size="small"
                      >查看</el-button
                    >
                    <el-button
                      v-if="scope.row.statusName !== '已上传' || scope.row.status === '正常'"
                      @click="removeItem(scope.row, 'ihcDataIng')"
                      type="text"
                      size="small"
                    >
                      <font color="red">删除</font>
                    </el-button>
                    <el-button
                      v-if="
                        (scope.row.status === '机构做' && isSendDoctor) ||
                          (scope.row.status === '已付款' && !isSendDoctor)
                      "
                      @click="itemCheck(scope.row, 'ihcDataIng')"
                      type="text"
                      size="small"
                      >{{ scope.row.statusName === '已上传' ? '重新上传' : '上传' }}
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column prop="statusName" label="当前状态" width="80"> </el-table-column>
                <el-table-column prop="submitDate" label="提交时间"> </el-table-column>
                <el-table-column prop="status" label="订单状态"> </el-table-column>
                <el-table-column label="备注" width="300">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.result"
                      placeholder="请输入备注"
                      class="input-form"
                      size="mini"
                    ></el-input>
                    <el-button
                      v-if="
                        (scope.row.status === '机构做' && isSendDoctor) ||
                          (scope.row.status === '已付款' && !isSendDoctor)
                      "
                      @click="saveRemark(scope.row)"
                      type="text"
                      size="small"
                      style="margin-left: 10px"
                      >保存</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
          </el-tabs>
        </template>
      </el-row>
      <!-- <el-row style="margin: 20px 0" id="participateMeeting">
        <div class="content-text">诊断流转</div>
        <template>
          <el-table :data="participateMeetData" border style="width: 100%">
            <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
            <el-table-column prop="jobtitle" label="职称" width="170"> </el-table-column>
            <el-table-column prop="service" label="医院" width="190"> </el-table-column>
            <el-table-column prop="role" label="角色"> </el-table-column>
            <el-table-column prop="time" label="加入时间"> </el-table-column>
          </el-table>
        </template>
      </el-row> -->
    </el-row>
    <!-- 加做特殊染色弹窗 -->
    <el-dialog
      :close-on-click-modal="false"
      title="选择特殊染色"
      :visible.sync="addstainingdialog"
      width="90%"
      :modal-append-to-body="false"
      :append-to-body="true"
    >
      <div style="height: 300px">
        <template>
          <div
            style="
              float: left;
              width: 48%;
              height: 320px;
              border-bottom: 1px solid #ccc;
              border-left: 1px solid #ccc;
              border-top: 1px solid #ccc;
            "
          >
            <div>
              <div style="margin-left: 10px">
                <div style="padding-top: 5px">
                  <el-input
                    style="float: left; width: 50%"
                    size="mini"
                    v-model="staningkeySearch"
                    placeholder="输入关键字……"
                    clearable
                  ></el-input>
                  <el-button
                    @click="addDyeingHandelClick"
                    type="primary"
                    style="margin-left: 5px"
                    size="mini"
                    >搜索</el-button
                  >
                </div>
                <div style="margin-top: 20px; height: 250px; overflow-y: auto; margin-bottom: 12px">
                  <template>
                    <el-checkbox-group
                      class="checkbox"
                      v-model="checkedstaning"
                      @change="handleCheckedstaningChange"
                    >
                      <el-checkbox
                        style="display: block; margin-left: 30px; line-height: 20px"
                        v-for="(item, index) in staningDatas"
                        :label="item.id"
                        :key="index"
                      >
                        <div>
                          <div class="limit-text" :title="item.name">
                            {{ item.name }}
                          </div>
                          <div class="limit-count-text">价格:{{ item.cost }}元</div>
                        </div>
                      </el-checkbox>
                    </el-checkbox-group>
                  </template>
                </div>
              </div>
            </div>
          </div>
        </template>
        <template>
          <div
            style="
              float: left;
              width: 48%;
              height: 320px;
              border-bottom: 1px solid #ccc;
              border-left: 1px solid #ccc;
              border-right: 1px solid #ccc;
            "
          >
            <div
              style="
                height: 38px;
                line-height: 38px;
                border-top: 1px solid #ccc;
                border-bottom: 1px solid #ccc;
              "
            >
              <span>已选项目</span
              ><span style="margin-left: 15px">总计:{{ staningPriceTotal }}元</span>
            </div>
            <div style="margin-top: 20px; margin-left: 10px">
              <div style="height: 32px; line-height: 32px">
                <div style="height: 32px; float: left; line-height: 32px">单项</div>
              </div>
              <ul style="height: 176px; overflow-y: auto; margin-bottom: 12px">
                <li :key="item.id" v-for="item in staningDatasCopy">
                  <span class="limit-text">{{ item.name }}</span>
                  <span>价格:{{ item.cost }}元</span>
                </li>
              </ul>
            </div>
          </div>
        </template>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="addstainingdialog = false">取 消</el-button>
        <el-button size="mini" @click="addType('staining')" type="primary">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 加做信息 分子病理弹窗-->
    <el-dialog
      :close-on-click-modal="false"
      title="选择分子病理"
      :visible.sync="addmolecular"
      width="90%"
      :modal-append-to-body="false"
      :append-to-body="true"
    >
      <div style="height: 300px">
        <template>
          <div
            style="
              float: left;
              width: 48%;
              height: 320px;
              border-bottom: 1px solid #ccc;
              border-left: 1px solid #ccc;
              border-top: 1px solid #ccc;
            "
          >
            <el-tabs v-model="addmolecularName" @tab-click="molecularhandleClick">
              <el-tab-pane label="套餐" name="first">
                <div>
                  <div style="margin-left: 10px">
                    <div
                      style="margin-top: 20px; height: 240px; overflow-y: auto; margin-bottom: 12px"
                    >
                      <template>
                        <el-checkbox-group
                          class="checkbox"
                          v-model="molecularChecked"
                          @change="handleCheckedmolecularChange"
                        >
                          <el-checkbox
                            style="display: block; margin-left: 30px; line-height: 20px"
                            v-for="(item, index) in molecularAll"
                            :label="item.id"
                            :key="index"
                          >
                            <div>
                              <div class="limit-text" :title="item.name">
                                {{ item.name }}
                              </div>
                              <div class="limit-count-text">价格:{{ item.discount }}元</div>
                            </div>
                          </el-checkbox>
                        </el-checkbox-group>
                      </template>
                    </div>
                  </div>
                </div>
              </el-tab-pane>
              <el-tab-pane label="单项" name="second">
                <div>
                  <div style="margin-left: 10px">
                    <!-- <div style="padding-top: 5px;">
                                            <el-input style="float: left; width: 50%;" size="mini"
                                                      v-model="molecularPkgSearchKey"
                                                      placeholder="输入关键字……"
                                                      clearable></el-input>
                                            <el-button @click="molecularPkgSearchByName"
                                            type="primary" style="margin-left: 5px" size="mini">
                                            搜索</el-button>
                                        </div> -->
                    <div
                      style="margin-top: 20px; height: 200px; overflow-y: auto; margin-bottom: 12px"
                    >
                      <template>
                        <!-- <el-checkbox
                                                :indeterminate="staningisIndeterminate"
                                                v-model="staningcheckAll"
                                                @change="staninghandleCheckAllChange">全选
                                                </el-checkbox>
                                                <div style="margin: 15px 0;"></div> -->
                        <el-checkbox-group
                          class="checkbox"
                          v-model="molecularCheckedDataCopyIdS"
                          @change="molecularSubCheckedChange"
                        >
                          <el-checkbox
                            style="display: block; margin-left: 30px; line-height: 20px"
                            v-for="(item, index) in molecularSubData"
                            :label="item.id"
                            :key="index"
                          >
                            <div>
                              <div class="limit-text" :title="item.name">
                                {{ item.name }}
                              </div>
                              <div class="limit-count-text">价格:{{ item.cost }}元</div>
                            </div>
                          </el-checkbox>
                        </el-checkbox-group>
                      </template>
                    </div>
                  </div>
                </div>
              </el-tab-pane>
            </el-tabs>
          </div>
        </template>
        <template>
          <div
            style="
              float: left;
              width: 48%;
              height: 320px;
              border-bottom: 1px solid #ccc;
              border-left: 1px solid #ccc;
              border-right: 1px solid #ccc;
            "
          >
            <div
              style="
                height: 38px;
                line-height: 38px;
                border-top: 1px solid #ccc;
                border-bottom: 1px solid #ccc;
              "
            >
              <span>已选项目</span><span style="margin-left: 15px">总计:{{ moleculaTotal }}元</span>
            </div>
            <div style="margin-left: 10px">
              <div style="height: 32px; line-height: 32px">
                <div style="height: 32px; float: left; line-height: 32px">单项</div>
              </div>
              <ul style="height: 210px; overflow-y: auto; margin-bottom: 12px">
                <li :key="index" v-for="(item, index) in molecularCheckedDataCopy">
                  <span class="limit-text">{{ item.name }}</span>
                  <span>价格:{{ item.cost }}元</span>
                  <span
                    v-if="addmolecularName === 'first'"
                    style="margin-left: 20px; color: #00f; cursor: pointer"
                    @click="decmolecularItem(item.id)"
                    >删除</span
                  >
                </li>
              </ul>
            </div>
          </div>
        </template>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="addmolecular = false">取 消</el-button>
        <el-button size="mini" @click="addType('molecular')" type="primary">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 加做信息 免疫组化弹窗-->
    <el-dialog
      :close-on-click-modal="false"
      title="选择免疫组化"
      :visible.sync="addImmunohistochemistry"
      width="90%"
      :modal-append-to-body="false"
      :append-to-body="true"
    >
      <div style="height: 300px">
        <template>
          <div
            style="
              float: left;
              width: 48%;
              height: 320px;
              border-bottom: 1px solid #ccc;
              border-left: 1px solid #ccc;
              border-top: 1px solid #ccc;
            "
          >
            <el-tabs v-model="addImmunohistochemistryactiveName" @tab-click="inchandleClick">
              <el-tab-pane label="套餐" name="first">
                <div>
                  <div style="margin-left: 10px">
                    <div
                      style="margin-top: 20px; height: 240px; overflow-y: auto; margin-bottom: 12px"
                    >
                      <template>
                        <el-checkbox-group
                          class="checkbox"
                          v-model="ihcChecked"
                          @change="handleCheckedIhcChange"
                        >
                          <el-checkbox
                            style="display: block; margin-left: 30px; line-height: 20px"
                            v-for="(item, index) in ihcAll"
                            :label="item.id"
                            :key="index"
                          >
                            <div>
                              <div class="limit-text" :title="item.name">
                                {{ item.name }}
                              </div>
                              <div class="limit-count-text">价格:{{ item.cost }}元</div>
                            </div>
                          </el-checkbox>
                        </el-checkbox-group>
                      </template>
                    </div>
                  </div>
                </div>
              </el-tab-pane>
              <el-tab-pane label="单项" name="second">
                <div>
                  <div style="margin-left: 10px">
                    <div style="padding-top: 5px">
                      <el-input
                        style="float: left; width: 50%"
                        size="mini"
                        v-model="ihcPkgSearchKey"
                        placeholder="输入关键字……"
                        clearable
                      ></el-input>
                      <el-button
                        @click="inchandleClick"
                        type="primary"
                        style="margin-left: 5px"
                        size="mini"
                        >搜索</el-button
                      >
                    </div>
                    <div
                      style="margin-top: 20px; height: 200px; overflow-y: auto; margin-bottom: 12px"
                    >
                      <template>
                        <!-- <el-checkbox
                                                :indeterminate="staningisIndeterminate"
                                                v-model="staningcheckAll"
                                                @change="staninghandleCheckAllChange">全选
                                                </el-checkbox>
                                                <div style="margin: 15px 0;"></div> -->
                        <el-checkbox-group
                          class="checkbox"
                          v-model="ihcCheckedDataCopyIdS"
                          @change="ihcSubCheckedChange"
                        >
                          <el-checkbox
                            style="display: block; margin-left: 30px; line-height: 20px"
                            v-for="(item, index) in ihcSubData"
                            :label="item.id"
                            :key="index"
                          >
                            <div>
                              <div class="limit-text" :title="item.name">
                                {{ item.name }}
                              </div>
                              <div class="limit-count-text">价格:{{ item.cost }}元</div>
                            </div>
                          </el-checkbox>
                        </el-checkbox-group>
                      </template>
                    </div>
                  </div>
                </div>
              </el-tab-pane>
            </el-tabs>
          </div>
        </template>
        <template>
          <div
            style="
              float: left;
              width: 48%;
              height: 320px;
              border-bottom: 1px solid #ccc;
              border-left: 1px solid #ccc;
              border-right: 1px solid #ccc;
            "
          >
            <div
              style="
                height: 38px;
                line-height: 38px;
                border-top: 1px solid #ccc;
                border-bottom: 1px solid #ccc;
              "
            >
              <span>已选项目</span><span style="margin-left: 15px">总计:{{ ihcTotal }}元</span>
            </div>
            <div style="margin-left: 10px">
              <div style="height: 32px; line-height: 32px">
                <div style="height: 32px; float: left; line-height: 32px">单项</div>
              </div>
              <ul style="height: 210px; overflow-y: auto; margin-bottom: 12px">
                <li :key="index" v-for="(item, index) in ihcCheckedDataCopy">
                  <span class="limit-text">{{ item.name }}</span>
                  <span>价格:{{ item.cost }}元</span>
                  <span
                    v-if="addImmunohistochemistryactiveName === 'first'"
                    style="margin-left: 20px; color: #00f; cursor: pointer"
                    @click="decIncItem(item.id)"
                    >删除</span
                  >
                </li>
              </ul>
            </div>
          </div>
        </template>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="addImmunohistochemistry = false">取 消</el-button>
        <el-button size="mini" @click="addType('ihc')" type="primary">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 上传资料 -->
    <el-dialog
      :close-on-click-modal="false"
      title="上传资料"
      :visible.sync="showUploadData"
      width="90%"
      @closed="cancelToUpload"
    >
      <el-upload
        v-if="personAuth === 'doctor'"
        ref="addItemDataUpload"
        multiple
        :action="`${imageURL}/upload`"
        :on-change="changeImages"
        :file-list="dialogImages"
        list-type="picture-card"
      >
        <el-button size="small" type="primary">点击上传</el-button>
      </el-upload>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click="commitAppPic">提交</el-button>
        <el-button size="mini" @click="cancelToUpload">返回</el-button>
      </span>
    </el-dialog>

    <!-- 查看资料 -->
    <el-dialog
      :close-on-click-modal="false"
      title="查看资料"
      :visible.sync="lookshowUploadData"
      width="50%"
    >
      <viewer :images="dialogImages" ref="viewer">
        <img
          v-for="(img, index) in dialogImages"
          :src="img.url"
          :key="index"
          style="max-width: 100px; max-height: 100px; margin: 10px"
        />
      </viewer>

      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="lookshowUploadData = false">返回</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
/**
 * author：duyanzhao
 */

// import moment from 'moment';

export default {
  name: 'ConsultationPlus',
  components: {},
  props: ['orderId', 'orders', 'diagnosisId'],
  data() {
    return {
      userId: this.$store.state.user.id,
      TransferDataKey: {},
      suggesstionStaining: [],
      staining: [],
      molecularDetial: [],
      //参与人员
      participateMeetDataIng: [],
      imgURL: '',
      TransferData: '',
      // 查看加做信息相关
      addItemCheckTab: 'addDyeing',
      imageURL: process.env.VUE_APP_ImageServiceURL, // 图片上传地址:
      showUploadData: false,
      lookshowUploadData: false,
      dialogImages: [],
      // 特殊染色弹窗
      addstainingdialog: false,
      staningkeySearch: '',
      staningisIndeterminate: true,
      staningcheckAll: false,
      checkedstaning: [],
      staningDatas: [],
      staningDatasCopy: [],
      staningPriceTotal: 0,
      // 分子病理弹窗相关属性
      addmolecular: false,
      addmolecularName: 'first',
      molecularChecked: [],
      molecularAll: [],
      molecularCheckedDataCopy: [],
      molecularCheckedDataCopyIdS: [],
      molecularSubData: [],
      molecularDataIng: [],
      molecularPkgSearchKey: '',
      // 免疫组化弹窗相关属性
      addImmunohistochemistry: false,
      addImmunohistochemistryactiveName: 'first',
      ihcChecked: [],
      ihcAll: [],
      ihcCheckedDataCopy: [],
      ihcCheckedDataCopyIdS: [],
      ihcSubData: [],
      ihcDataIng: [],
      ihcPkgSearchKey: '',
      isSendDoctor: false
    }
  },
  watch: {
    diagnosisId: {
      handler: function(newVal) {
        if (newVal) {
          this.getmedicalorder(this.orders?.patients?.[0]?.extraProjectInfos)
        }
      }
    }
  },
  mounted() {
    this.isSendDoctor = this.userId === this.orders.userId ? true : false
    this.getParticipant()
  },

  computed: {
    // 处理特殊染色的属性
    stainingData() {
      return this.staining.map(item => ({
        projectName: item.doctorAdviceName,
        ids: item.id,
        statusName: item.resultUrl ? '已上传' : '结果图片未上传',
        specialistId: item.applyDoctorName,
        url: item.resultUrl,
        submitDate: item.createTime,
        type: 'staining',
        status: item.status == 0 ? '正常' : item.status == 1 ? '机构做' : '已付款',
        result: item.result
      }))
    },
    fzblData() {
      const data = []
      if (this.molecularDetial.length > 0) {
        this.molecularDetial.forEach(item => {
          let statusName = ''
          if (item.resultUrl) {
            statusName = '已上传'
          } else {
            statusName = '结果图片未上传'
          }
          data.push({
            projectName: item.doctorAdviceName,
            ids: item.id,
            statusName,
            specialistId: item.applyDoctorName,
            url: item.resultUrl,
            submitDate: item.createTime,
            type: 'molecular',
            status: item.status == 0 ? '正常' : item.status == 1 ? '机构做' : '已付款',
            result: item.result
          })
        })
      }
      return data
    },
    //参与人员
    participateMeetData() {
      const data = []
      if (this.participateMeetDataIng.length > 0) {
        this.participateMeetDataIng.forEach(item => {
          data.push({
            jobtitle: item.roleName,
            name: item.expertName,
            service: item.institutionName,
            time: item.createTime,
            role: item.roleName
          })
        })
      }
      return data
    },
    ihcData() {
      const data = []
      if (this.ihcDataIng.length > 0) {
        this.ihcDataIng.forEach(item => {
          let statusName = ''
          if (item.resultUrl) {
            statusName = '已上传'
          } else {
            statusName = '结果图片未上传'
          }
          data.push({
            projectName: item.doctorAdviceName,
            ids: item.id,
            url: item.resultUrl,
            statusName,
            specialistId: item.applyDoctorName,
            submitDate: item.createTime,
            type: 'ihc',
            status: item.status == 0 ? '正常' : item.status == 1 ? '机构做' : '已付款',
            result: item.result
          })
        })
      }
      return data
    },
    personAuth() {
      let auth = 'doctor'
      return auth
    },
    moleculaTotal() {
      let price = 0
      if (this.molecularCheckedDataCopy.length > 0) {
        this.molecularCheckedDataCopy.forEach(temp => {
          price += temp.cost
        })
      }
      return price
    },
    ihcTotal() {
      let price = 0
      if (this.ihcCheckedDataCopy.length > 0) {
        this.ihcCheckedDataCopy.forEach(temp => {
          price += temp.cost
        })
      }
      return price
    }
  },
  methods: {
    //备注保存
    saveRemark(row) {
      debugger
      if (row.status !== '已付款' && row.status !== '机构做') {
        this.$message.warning('未付款不可保存结果')
      } else if (row.status === '机构做') {
        if (!this.isSendDoctor) {
          this.$message.warning('需申请机构保存此备注')
        }
      } else if (row.status === '已付款') {
        if (this.isSendDoctor) {
          this.$message.warning('需会诊机构保存此备注')
        } else {
          let _this = this
          this.$axios({
            method: 'put',
            url: '/diagnosis/extra-project',
            data: { id: row.ids, result: row.result }
          }).then(
            res => {
              if (res.data.code === 200) {
                _this.$message.success('保存成功')
                location.reload()
                // this[this.TransferDataKey].forEach((n, i) => {
                //   if (n.id == _this.TransferData) {
                //     this.$set(this[this.TransferDataKey][i], 'resultUrl', _this.imgURL + '|')
                //   }
                // })
              }
            },
            err => {
              this.$message.info(`${err.response.data}`)
            }
          )
        }
      }
    },
    // 分子病理
    molecularhandleClick(tab) {
      if (tab.label === '单项') {
        try {
          this.$axios({
            method: 'POST',
            url: `/doctor-advices/findAllDoctorAdvice`,
            data: {
              name: this.molecularPkgSearchKey,
              type: 2,
              size: 100,
              page: 0
            }
          }).then(
            res => {
              if (res.data.code === 200) {
                // 设置数据列表
                this.molecularSubData = res.data.data
              }
            },
            err => {
              this.$message.info(err.response.data)
            }
          )
        } catch (e) {
          console.log('请求失败')
        }
      }
    },

    // 获取分子病理
    addMolecularHandelClick() {
      try {
        this.$axios({
          method: 'get',
          url: '/doctor-advice-packages?name=&type=2&size=1000&page=0'
        }).then(
          res => {
            if (res.data.code === 200) {
              // 设置数据列表
              this.molecularAll = res.data.data
              this.addmolecular = true
            }
          },
          err => {
            this.$message.info(err.response.data)
          }
        )
      } catch (e) {
        console.log('请求失败')
      }
    },
    handleCheckedmolecularChange(val) {
      this.molecularCheckedDataCopy = []
      this.molecularCheckedDataCopyIdS = []
      if (val.length > 0) {
        val.forEach(id => {
          this.molecularAll.forEach(eid => {
            if (eid.id === id) {
              eid.doctorAdviceList.forEach(temp => {
                this.molecularCheckedDataCopy.push(temp)
                this.molecularCheckedDataCopyIdS.push(temp.id)
              })
            }
          })
        })
      }
    },
    molecularSubCheckedChange(val) {
      this.molecularCheckedDataCopy = []
      this.molecularSubData.forEach(item => {
        val.forEach(temp => {
          if (temp === item.id) {
            this.molecularCheckedDataCopy.push(item)
          }
        })
      })
    },
    decmolecularItem(val) {
      if (this.molecularCheckedDataCopy.length === 1) {
        this.molecularCheckedDataCopy = []
      } else {
        for (let i = 0; i < this.molecularCheckedDataCopy.length - 1; i++) {
          if (this.molecularCheckedDataCopy[i].id === val) {
            this.molecularCheckedDataCopy.splice(i, 1)
          }
        }
      }
    },
    addMesHandleClick() {
      this.dialogImages = []
    },
    // 免疫组化
    addIncHandelClick() {
      try {
        this.$axios({
          method: 'get',
          url: '/doctor-advice-packages?name=&type=3&size=1000&page=0'
        }).then(
          res => {
            if (res.data.code === 200) {
              // 设置数据列表
              this.ihcAll = res.data.data
              this.addImmunohistochemistry = true
            }
          },
          err => {
            this.$message.info(err.response.data)
          }
        )
      } catch (e) {
        console.log('请求失败')
      }
    },
    inchandleClick(tab) {
      if (tab.label === '单项') {
        // 请求查询接口
        try {
          this.$axios({
            method: 'POST',
            url: `/doctor-advices/findAllDoctorAdvice`,
            data: {
              name: this.ihcPkgSearchKey,
              type: 3,
              size: 100,
              page: 0
            }
          }).then(
            res => {
              if (res.data.code === 200) {
                // 设置数据列表
                this.ihcSubData = res.data.data
              }
            },
            err => {
              this.$message.info(err.response.data)
            }
          )
        } catch (e) {
          console.log('请求失败')
        }
      }
    },
    handleCheckedIhcChange(val) {
      this.ihcCheckedDataCopy = []
      this.ihcCheckedDataCopyIdS = []
      if (val.length > 0) {
        val.forEach(id => {
          this.ihcAll.forEach(eid => {
            if (eid.id === id) {
              eid.doctorAdviceList.forEach(temp => {
                this.ihcCheckedDataCopy.push(temp)
                this.ihcCheckedDataCopyIdS.push(temp.id)
              })
            }
          })
        })
      }
    },
    ihcPkgSearchByName() {},
    ihcSubCheckedChange(val) {
      this.ihcCheckedDataCopy = []
      this.ihcSubData.forEach(item => {
        val.forEach(temp => {
          if (temp === item.id) {
            this.ihcCheckedDataCopy.push(item)
          }
        })
      })
    },
    decIncItem(val) {
      if (this.ihcCheckedDataCopy.length === 1) {
        this.ihcCheckedDataCopy = []
      } else {
        for (let i = 0; i < this.ihcCheckedDataCopy.length - 1; i++) {
          if (this.ihcCheckedDataCopy[i].id === val) {
            this.ihcCheckedDataCopy.splice(i, 1)
          }
        }
      }
    },
    // 处理加做项目数据
    processingData(id, list = []) {
      return list
        .filter(n => n.consultationId == id)
        .reduce(
          (arr, n) => {
            arr[Number(n.type) - 1].push({ ...n })
            return arr
          },
          [[], [], []]
        )
    },

    // 获取特殊医嘱
    getmedicalorder(list = []) {
      const [arr1, arr2, arr3] = this.processingData(this.diagnosisId, list)
      this.staining = arr1
      this.molecularDetial = arr2
      this.ihcDataIng = arr3
      let arrList = []
      arr1.forEach(item => {
        arrList.push(item)
      })
      arr2.forEach(item => {
        arrList.push(item)
      })
      arr3.forEach(item => {
        arrList.push(item)
      })
      this.$emit('addPlus', arrList)
    },

    //获取参与人员
    getParticipant() {
      this.participateMeetDataIng = []
      this.participateMeetDataIng = this.orders.patients[0].expertDiagnosis
      this.getmedicalorder(this.orders?.patients?.[0]?.extraProjectInfos)
    },

    removeItem(item, key) {
      const msg = '确认是否要移除此加做项目'
      this.$confirm(msg, '删除提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          try {
            this.$axios({
              method: 'DELETE',
              url: `/diagnosis/extra-project/${item.ids}`
            }).then(
              res => {
                if (res.data.code === 200) {
                  this.$message.success('删除成功')
                  this.updateExtraProjectInfos()
                  //   this[key] = this[key].filter(n => n.id != item.ids)
                }
              },
              err => {
                this.$message.info(err.response.data)
              }
            )
          } catch (e) {
            console.log('请求失败')
          }
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '取消操作'
          })
        })
    },
    // 查看上传图片
    LookItemCheck(item) {
      if (item.url) {
        this.dialogImages = []
        const imgList = item.url.split('|')
        const formatList = imgList.slice(0, -1)
        formatList.forEach(ele => {
          this.dialogImages.push({ name: 'img', url: this.imageURL + ele })
        })
      }
      this.lookshowUploadData = true
    },
    itemCheck(item, key) {
      console.log(key)
      this.showUploadData = true
      this.TransferData = item.ids
      this.TransferDataKey = key
      if (item.url) {
        this.clearUploadFiles()
        this.dialogImages = []
        const imgList = item.url.split('|')
        const formatList = imgList.slice(0, -1)
        formatList.forEach(ele => {
          this.dialogImages.push({ name: 'img', url: this.imageURL + ele })
        })
      }
    },
    updateExtraProjectInfos() {
      this.$axios({
        method: 'GET',
        url: `/diagnosis/extra-project/${this.orders.patients[0].id}`
      }).then(
        res => {
          if (res.data.code === 200) {
            this.getmedicalorder(res.data?.data || [])
          }
        },
        err => {
          this.$message.info(`${err.response.data}`)
        }
      )
    },

    commitAppPic() {
      // url修正为服务器返回链接
      let _this = this
      try {
        this.$axios({
          method: 'put',
          url: '/diagnosis/extra-project',
          data: { id: _this.TransferData, resultUrl: _this.imgURL }
        }).then(
          res => {
            if (res.data.code === 200) {
              _this.$message.info('添加成功')
              _this.showUploadData = false
              this[this.TransferDataKey].forEach((n, i) => {
                if (n.id == _this.TransferData) {
                  this.$set(this[this.TransferDataKey][i], 'resultUrl', _this.imgURL)
                }
              })
            }
          },
          err => {
            this.$message.info(`${err.response.data}`)
          }
        )
      } catch (e) {
        console.log('请求失败')
      }
    },
    addDyeingHandelClick() {
      try {
        this.$axios({
          method: 'POST',
          url: `/doctor-advices/findAllDoctorAdvice`,
          data: {
            name: this.staningkeySearch,
            type: 1,
            size: 100,
            page: 0
          }
        }).then(
          res => {
            if (res.data.code === 200) {
              // 设置数据列表
              this.staningDatas = res.data.data
              // 初始化已经选择的
              if (this.staining.length > 0) {
                const tempdata = []
                this.staining.forEach(item => {
                  tempdata.push(item.id)
                })
                this.checkedstaning = tempdata
                this.handleCheckedstaningChange(tempdata)
              }
            }
            this.addstainingdialog = true
          },
          err => {
            this.$message.info(err.response.data)
          }
        )
      } catch (e) {
        console.log('请求失败')
      }
    },
    handleCheckedstaningChange(value) {
      this.staningDatasCopy = []
      if (this.staningDatas) {
        this.staningDatas.forEach(item => {
          value.forEach(temp => {
            if (item.id === temp) {
              this.staningDatasCopy.push(item)
            }
          })
        })
      }
      let staningPriceTotal = 0
      this.staningDatasCopy.forEach(item => {
        staningPriceTotal = item.cost + staningPriceTotal
      })

      this.staningPriceTotal = staningPriceTotal
      const checkedCount = value.length
      this.staningcheckAll = checkedCount === this.staningDatas.length
      this.staningisIndeterminate = checkedCount > 0 && checkedCount < this.staningDatas.length
    },
    cancelToUpload() {
      this.clearUploadFiles()
      this.showUploadData = false
    },
    clearUploadFiles() {
      if (this.personAuth === 'doctor') {
        this.$refs.addItemDataUpload.clearFiles()
      }
    },
    changeImages(file, fileList) {
      this.imgURL = ''
      if (file.status === 'success') {
        fileList.forEach(ele => {
          if (ele.response) {
            this.imgURL += `${ele.response.url.slice(ele.response.url.indexOf('_') - 1)}|`
          }
        })
      }
    },
    addType(type) {
      let finallyData = []
      const words = []
      if (type === 'staining') {
        finallyData = this.staningDatasCopy
        this.staningDatasCopy.forEach(temp => {
          words.push(temp.id)
        })
      }
      if (type === 'ihc') {
        finallyData = this.ihcCheckedDataCopy
        this.ihcCheckedDataCopy.forEach(temp => {
          words.push(temp.id)
        })
      }
      if (type === 'molecular') {
        finallyData = this.molecularCheckedDataCopy
        this.molecularCheckedDataCopy.forEach(temp => {
          words.push(temp.id)
        })
      }
      if (finallyData.length > 0) {
        try {
          this.$axios({
            method: 'post',
            url: `/diagnosis/extra-project?doctorAdviceIds=${words.join()}&patientsId=${
              this.orders.patients[0].id
            }&diagnosisId=${this.diagnosisId}`
          }).then(
            res => {
              if (res.data.code === 200) {
                this.$message.success('添加成功')
                this.updateExtraProjectInfos()
                this.addstainingdialog = false
                this.addmolecular = false
                this.addImmunohistochemistry = false
              }
            },
            err => {
              this.$message.info(`${err.response.data}`)
            }
          )
        } catch (e) {
          console.log('请求失败')
        }
      } else {
        this.$message({
          message: '请选择加做项目',
          type: 'warning'
        })
      }
    }
  }
}
</script>

<style scoped>
.limit-text {
  width: 320px;
  display: inline-block;
  vertical-align: middle;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.limit-count-text {
  display: inline-block;
  vertical-align: middle;
}

.content-text {
  margin-bottom: 15px;
}
</style>
